{% extends "admin/change_form.html" %}
{% load i18n admin_urls static admin_modify %}
{% block after_field_sets %}
    <input type='text' style='display: none' id='action' name='action' value='0'></input>
    {% if is_edit is True %}
        <div class="inline-group " id="toolsexecjob_set-group">
            <h2>目标主机</h2>
            <div class="inline-related dynamic-toolsexecjob_set" id="toolsexecjob_set-0">
                <h3><b>目标主机:</b>&nbsp;
                </h3>
                <fieldset class="module aligned first ">
                    <div class="control-group form-row field-hosts ">
                        <div>
                            <div class="control-label"><label class="required"
                                                              for="id_toolsexecjob_set-0-hosts">目标主机:</label>
                            </div>
                            <div class="controls">
                                <div class="related-widget-wrapper">
                                    <select multiple="multiple"
                                            id="sls_hosts"
                                            name="sls_hosts">
                                        {% for obj in hostList %}
                                            <option value="{{ obj.id }}">{{ obj.host_name }}</option>
                                        {% endfor %}
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                    {% for k,v in param %}
                        <div class="control-group form-row field-param ">
                            <div>
                                <div class="control-label"><label
                                        for="id_toolsexecjob_set-0-param">{{ k }}:</label></div>
                                <div class="controls">

                                    <input class="vTextField" name="{{ v }}" required value="" placeholder="{{ v }}">

                                </div>
                            </div>
                        </div>
                    {% endfor %}
                </fieldset>
            </div>
        </div>
    {% endif %}
{% endblock %}


{% block inline_field_sets %}
    {{ block.super }}
    <script>
        {% if is_edit is True %}

            var jq;
            (function ($) {
                $(document).ready(function ($) {
                    $('.submit-row').append("<button type='submit' class='button' onclick='return setValue()'>执行工具</button>")
                    jq = $;

                });
            })(django.jQuery);

            function setValue() {
                debugger;
                if (jq("#sls_hosts").find('option:selected').length > 0) {
                    document.getElementById("action").value = 1;
                    return true
                } else {
                    alert("请选择需要执行工具的目标主机");
                    return false
                }

            }
        {% endif %}
    </script>
{% endblock %}